package com.xyht.sca_s.student_manage_system.modules.clockIn.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.clockIn.entity.req.SmsClockInReq;
import com.xyht.sca_s.student_manage_system.modules.clockIn.service.SmsClockInService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 打卡记录表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-08-03
 */
@RestController
@RequestMapping("/clockIn")
@SecretBody
public class SmsClockInController {

    @Resource
    private SmsClockInService smsClockInService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;


    @ApiModelProperty("查看打卡")
    @GetMapping("/getClockInInfo")
    public ResponseResult getClockInInfo(HttpServletRequest request,
                                         @RequestParam(value = "clockInLongitude",required = false) String clockInLongitude,
                                         @RequestParam(value = "clockInLatitude",required = false) String clockInLatitude,
                                         @RequestParam(value = "clockInDate",required = false) String clockInDate){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsClockInService.getClockInInfo(userId,clockInLongitude,clockInLatitude,clockInDate);
    }

    @ApiModelProperty("打卡")
    @PostMapping("/startClockIn")
    public ResponseResult startClockIn(HttpServletRequest request, @RequestBody SmsClockInReq smsClockInReq){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsClockInService.startClockIn(userId,smsClockInReq);
    }

    @ApiModelProperty("查看个人当月考勤统计")
    @GetMapping("/getThisStatistics")
    public ResponseResult getThisMonthStatistics(HttpServletRequest request,
                                                 @RequestParam(value = "clockInDate",required = false) String clockInDate,
                                                 @RequestParam(value = "clockInState",required = false) Integer clockInState){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsClockInService.getThisMonthStatistics(userId,clockInDate,clockInState);
    }
}

